﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lion
{
    public class Account : ICachedCollection<string, Account>
    {
        #region EntityMembers
        public virtual string ID { get; set; }
        public virtual string Name { get; set; }
        public virtual AccountCategory AccountCategory { get; set; }
        public bool IsActive { get; set; }
        public AccountType Type { get; set; }
        #endregion

        private static Dictionary<string, Account> _All;
        public static Dictionary<string, Account> All
        {
            get
            {
                if (null == _All)
                {
                    _All = ObjectAssembler.GetAllObjects<Account>()
                            .ToDictionary(c => c.ID, c => c);

                }
                return _All;
            }
            set { _All = value; }
        }
        public void ClearCollection()
        {
            _All = null;
        }
        public string VisualName
        {

            get
            {
                return this.ToString();
            }

        }


        public void AddToCache(string ID, Account Value)
        {
            _All[ID]= Value;
        }

        public bool RemoveFromCache(string ID)
        {
            return _All.Remove(ID);
        }

        public override string ToString()
        {
            return this.ID + "(" + this.Name + ")";
        }

        public override bool Equals(object obj)
        {
            Account account = obj as Account;
            if (null != account)
            {
                return account.ID == this.ID;
            }
            return false;
        }
        public override int GetHashCode()
        {
            return this.ID.GetHashCode();
        }
    }
}
